Flash Article

Bike Trips Sample Application: Using the XMLConnector Component in Flash MX Professional 2004


Table of Contents

  1. Introduction
  2. Getting Started: Examining the Bike Trips Application and Its Data
  3. Configuring the Application to Use the XMLConnector Component
  4. Binding XML Data to a ComboBox Component
  5. Creating ComboBox Labels Using XML Data
  6. Displaying and Updating a Trip Description in a TextArea Component
  7. Displaying and Updating a Formatted Cost in a TextInput Component
  8. Displaying and Updating a Graphic in a Loader Component
  9. Summary and Related Articles and Resources

Displaying and Updating a Trip Description in a TextArea Component

  1. Save XMLConnector_step2.fla as XMLConnector_step3.fla.
  2. Open the Components panel, drag an instance of the TextArea component onto the Stage, and drop it below the word "Description."
  3. Open the Property inspector for this new TextArea instance and set the following values:

    • Instance Name: taDescription
    • Width: 275
    • Height: 75
    • Editable: false

    Note: While you can set default text (even HTML-formatted text) for a TextArea component, do not do so here because the xcTrips XMLConnector component will provide these values dynamically, and users will specify them using the cbTrips ComboBox.

  4. Expose the description property from trip:Array in xcTrips as an available binding:

    1. Select xcTrips.
    2. Open the Component Inspector panel and select the Bindings tab.
    3. Press the Plus (+) button to add a new data binding, exposing the imported XML data schema, which you previously bound to xcTrips.
    4. Select the description property in the array of trip objects (called trip:Array) from the schema and click OK.
    5. You should now see the results.trips.trip.[n].description property of xcTrips listed as a binding available from xcTrips.
  5. Attach the newly exposed binding to the text property of the taDescription TextArea component:

    1. Select the xcTrips XMLConnector component. Select the results.trips.trip.[n].description binding from the Bindings tab in the Component Inspector panel.
    2. In the Bindings property grid, below the binding, set the direction property for this binding to "out."
    3. Select the bound to property and click the magnifying glass button.
    4. In the Bound To dialog box, set the following:

      • Component Path: TextArea <taDescription>
      • Schema Location: text : String
    5. Press OK.
  6. Select Control > Test Movie to test your application. Notice that the description for the first trip now appears in the taDescription TextArea component. However, if you select a different value in cbTrips, the description displayed in taDescription does not yet update.

    taDescription TextArea component with napa text.

    Figure 4. taDescription TextArea component with napa text.

  7. To make the currently selected row in cbTrips determine which description displays in taDescription, use the selectedIndex property in cbTrips to pull the appropriate description from the array of trip objects in xcTrips. Because data bindings dynamically update when bound values change, the description will update whenever the trip name changes:

    1. Select the xcTrips XMLConnector component.
    2. Open the Component Inspector panel and select the Bindings tab.
    3. Select the results.trips.trip.[n].description binding.
    4. Select the Index for 'trip' property, and press the magnifying glass button./li>
    5. In the Bound Index dialogue, uncheck "use a constant value" and set the following:

      • Component Path: cbTrips ComboBox
      • Schema Location: selectedIndex : Number

    Bindings for xcTrips.

    Figure 5. Bindings for xcTrips.

  8. Note: If you test the application at this point, the description will be undefined until a user changes cbTrips once, then it will update as expected. You will next set a default selectedIndex value to ensure that data binds to taDescription when the application first loads.

  9. Set the default value of the selectedIndex property of cbTrips to zero, making this value available to drive the data binding for taDescription when the application first loads:

    1. Select the cbTrips ComboBox component.
    2. Open the Components Inspector panel and select the Schema tab.
    3. Select the selectedIndex:Number property.
    4. In the property grid set the default value to 0.
    5. Select Control > Test Movie to test your application. You should see the trip, "Napa," and its description "The incredible variety of Napa …" when the movie loads. As you change the trip name, the description should automatically update.
    6. Save your changes to XMLConnector_step3.fla.